<?php
declare(strict_types=1);

namespace app\middleware\api\admin;

class ApiAuthCheck
{
    /**
     * 处理请求
     *
     * @param \think\Request $request
     * @param \Closure       $next
     * @return \think\Response
     */
    public function handle($request, \Closure $next)
    {
        $admin_auth = \app\library\api\admin\Auth::instance();
        $route_info = $request->rule();
        if (!$admin_auth->check(strtolower($route_info->getRoute()), $request->x_token_user['id'])) {
            return api_response(-1, '抱歉，暂无权限！');
        }

        return $next($request);
    }
}
